//
//  PCUserInfoManager.m
//  PhotoCircle
//
//  Created by GL on 15/12/16.
//  Copyright © 2015年 wujungao. All rights reserved.
//

#import "PCUserInfoManager.h"
#import "PCUserModel.h"

@interface PCUserInfoManager ()
@property (nonatomic, strong) PCUserModel *mUserModel;

@end
@implementation PCUserInfoManager

+ (PCUserInfoManager*)sharedUserInfo
{
    static dispatch_once_t once = 0;
    static PCUserInfoManager * _sharedUserInfo = nil;
    dispatch_once(&once, ^{
        _sharedUserInfo = [[PCUserInfoManager alloc] init];
    });
    return _sharedUserInfo;
}

-(PCUserModel*)mUserModel
{
    if (!_mUserModel) {
        NSData *userinfoData = UserDefaults_GetObject(@"userinfoData");
        PCUserModel *userInfo = [NSKeyedUnarchiver unarchiveObjectWithData:userinfoData];
        _mUserModel = userInfo;
    }
    return _mUserModel;
}

- (BOOL)checkUserInfo
{
    NSData *userinfoData = UserDefaults_GetObject(@"userinfoData");
    return userinfoData? YES : NO;
}

- (void)cleanLocalUserInfo
{
    self.mUserModel = nil;
    UserDefaults_RemoveObject(@"userinfoData");
}

- (void)saveUserInfo:(PCUserModel *)userInfo
{
    NSData *userinfoData = [NSKeyedArchiver archivedDataWithRootObject:userInfo];
    UserDefaults_SetObject(userinfoData,@"userinfoData");
}

- (PCUserModel *)readUserInfo
{
    return self.mUserModel;
}


@end